package com.coderman.domainservice.blogtopic.app.executor;

import com.alibaba.fastjson.JSON;
import com.coderman.domainservice.blogtopic.app.command.PublishBlogCommentCmd;
import com.coderman.domainservice.blogtopic.app.command.PublishBlogSpecialColumnCmd;
import com.coderman.domainservice.blogtopic.client.dto.BlogCommentDTO;
import com.coderman.domainservice.blogtopic.client.dto.BlogSpecialColumnDTO;
import com.coderman.domainservice.blogtopic.domain.ability.BlogIndiceService;
import com.coderman.domainservice.blogtopic.domain.convertor.BlogCommentConvertor;
import com.coderman.domainservice.blogtopic.domain.convertor.BlogSpecialColumnConvertor;
import com.coderman.domainservice.blogtopic.domain.gataway.BlogRepository;
import com.coderman.domainservice.blogtopic.domain.model.event.provider.PublishBlogCommentEvent;
import com.coderman.domainservice.blogtopic.infrast.dubbo.BlogCheckAdapterService;
import com.coderman.domainservice.blogtopic.infrast.mq.Constants;
import com.coderman.domainservice.blogtopic.infrast.mq.provider.MqSendService;
import com.coderman.domainservice.member.domain.model.user.valueobject.IndiceEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description:
 * date: 2021/3/31
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Service
public class PublishBlogSpecialColumnCmdExe {
    @Autowired
    private BlogCheckAdapterService blogCheckAdapterService;

    @Autowired
    private BlogRepository blogRepository;

    @Autowired
    private BlogIndiceService blogIndiceService;

    @Autowired
    private MqSendService mqSendService;

    /**
     * 发布专栏命令执行入口
     * @param cmd
     * @return
     * 注意这里有事务操作
     */
    //@Transactional
    public String execute(PublishBlogSpecialColumnCmd cmd) {
        //1.数据校验
        check(cmd.getBlogSpecialColumnDTO());
        //2.调用gataway接口
        blogRepository.publishBlogSpecialColumn(BlogSpecialColumnConvertor.INSTANCE.dto2bo(cmd.getBlogSpecialColumnDTO()));

        //3.调用专栏审核接口
        String result = blogCheckAdapterService.checkBlogSpecialColumn(cmd.getBlogSpecialColumnDTO());
        if(result.equals("success")){

        }else {
            //4.给用户发送通知
        }

        return "success";
    }

    private String check(BlogSpecialColumnDTO blogSpecialColumnDTO){
        //数据校验
        //业务规则校验
        return "success";
    }
}
